import $http from '../../http/http.js'
import apiSetting from '../../http/apiSetting.js'
let dayjs = require('dayjs');
let app = getApp();

Page({
  data: {
    delBtnShow: true,
    form: {},
    list: []
  },
  onLoad(query) {
    console.log(query)
    this.infoQuery(query)
    this.data.query = query
  },
  onShow() {
    this.qualityControlGradeQuery(this.data.query);
  },
  // 获取上面信息的数据
  infoQuery(query) {
    const pages = getCurrentPages();
    let currPage = pages[pages.length - 1]; //当前页面
    let prevPage = pages[pages.length - 2]; //上一个页面
    let list = prevPage.data.list
    let form = list.find(n => {
      return n.id == query.id
    })
    console.log(form)
    this.setData({
      form: form
    })
  },
  // 查询质检记录列表
  qualityControlGradeQuery(query) {
    let that = this;
    $http(apiSetting.qualityControlGradeQuery, {
      pageId: 1, //	页码
      pageSize: 200, //	每页数
      parentId: query.id, //	质检结果ID
    }).then((data) => {
      console.log(data)
      if (data.code == '0') {
        that.setData({
          list: data.result.grade
        })
      }
    })
  },

  // 信息编辑
  infoEdit(e) {
    let id = e.target.dataset.id;
    dd.navigateTo({
      url: '/pages/qualityInfoAddEdit/qualityInfoAddEdit?type=edit&id=' + id
    })
  },
  // 结果编辑
  resEdit(e) {
    let type = e.target.dataset.type;
    let id = e.target.dataset.id;
    let parentId = e.target.dataset.parentId;
    dd.navigateTo({
      url: '/pages/qualityResultAddEdit/qualityResultAddEdit?type=' + type + '&id=' + id + '&parentId=' + parentId
    })
  }
});
